//获取所有新闻
export const getNewsLists = (data) => {
    return {type: 'GETNEWSLISTS', data}
}
export function fetchNewsLists(params) {
    return dispatch => {
        var url = 'http://localhost:3000/news/list';

        fetch(url, {method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body:params
    }).then(res => {
            return res.json()
        }).then(data => {
            dispatch(getNewsLists(data))
        })
    }
}
//获取新闻分类
export const getNewsClassify = (data) => {
    return {type: 'GETNEWSCLASSIFY', data}
}
export function fetchNewsClassify() {
    return dispatch => {
        var url = 'http://localhost:3000/classify/list/1';

        fetch(url, {method: 'get'}).then(res => {
            return res.json()
        }).then(data => {
            dispatch(getNewsClassify(data))
        })
    }
}
//新闻详情
export const getNewsDetail = (data) => {
    return {type: 'GETNEWSCDETAIL', data}
}
export function fetchNewsDetail(params) {
    return dispatch => {
        var url = 'http://localhost:3000/news/data/'+params;

        fetch(url, {method: 'get'}).then(res => {
            return res.json()
        }).then(data => {
            dispatch(getNewsDetail(data))
        })
    }
}
//获取分类名称
export const getNewsType = (data) => {
    return {type: 'GETNEWSTYPE', data}
}
export function fetchNewsType(params) {
    return dispatch => {
        var url = 'http://localhost:3000/classify/data/'+params;

        fetch(url, {method: 'get'}).then(res => {
            return res.json()
        }).then(data => {
            dispatch(getNewsType(data))
        })
    }
}